﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
    private TopTenManager ttm;
    private MovieManager mm;

    private String language;

    protected void Page_Load(object sender, EventArgs e)
    {
        ttm = new TopTenManager((debioscoopEntities)Session["db"]);
        mm = new MovieManager((debioscoopEntities)Session["db"]);


        language = Master.tl.getCurrentLanguage();

        repeaterTopTen.DataSource = ttm.getTopTenMovies();
        repeaterTopTen.DataBind();

        comingSoonRepeater.DataSource = mm.getMoviesComingSoon();
        comingSoonRepeater.DataBind();

        List<film> randomMovies = ttm.getRandomNewsItemMovies();

        lblNewsItemMenu1.Text = Util.WrapText(randomMovies[0].naam, 16);
        lblNewsItemMenu2.Text = Util.WrapText(randomMovies[1].naam, 16);
        lblNewsItemMenu3.Text = Util.WrapText(randomMovies[2].naam, 16);

        urlTitle1.Text = randomMovies[0].naam;
        urlTitle2.Text = randomMovies[1].naam;
        urlTitle3.Text = randomMovies[2].naam;

        bigImage1.ImageUrl = randomMovies[0].big_url;
        bigImage2.ImageUrl = randomMovies[1].big_url;
        bigImage3.ImageUrl = randomMovies[2].big_url;

        urlTitle1.NavigateUrl = Page.ResolveClientUrl("~/FilmInfo.aspx?movieID=" + randomMovies[0].film_id);
        urlTitle2.NavigateUrl = Page.ResolveClientUrl("~/FilmInfo.aspx?movieID=" + randomMovies[1].film_id);
        urlTitle3.NavigateUrl = Page.ResolveClientUrl("~/FilmInfo.aspx?movieID=" + randomMovies[2].film_id);

        lblDesc1.Text = mm.getSummary(randomMovies[0], language, 200);
        lblDesc2.Text = mm.getSummary(randomMovies[1], language, 200);
        lblDesc3.Text = mm.getSummary(randomMovies[2], language, 200);

        ratedRepeater1.DataSource = randomMovies[0].kijkwijzers;
        ratedRepeater1.DataBind();

        ratedRepeater2.DataSource = randomMovies[1].kijkwijzers;
        ratedRepeater2.DataBind();

        ratedRepeater3.DataSource = randomMovies[2].kijkwijzers;
        ratedRepeater3.DataBind();

        lblPreview1.Text = (randomMovies[0].preview.Equals("") )? "Geen trailer beschikbaar" : "<object width='450' height='250'>" +
                    "<param name='movie' value='http://www.youtube.com/v/" + randomMovies[0].preview + "'></param>" +
                    "<param name='wmode' value='transparent'></param>" +
                    "<embed src='http://www.youtube.com/v/" + randomMovies[0].preview + "' type='application/x-shockwave-flash' wmode='transparent' width='450' height='250'></embed>" +
                "</object>";
        lblPreview2.Text = (randomMovies[1].preview.Equals("")) ? "Geen trailer beschikbaar" : "<object width='450' height='250'>" +
                    "<param name='movie' value='http://www.youtube.com/v/" + randomMovies[1].preview + "'></param>" +
                    "<param name='wmode' value='transparent'></param>" +
                    "<embed src='http://www.youtube.com/v/" + randomMovies[1].preview + "' type='application/x-shockwave-flash' wmode='transparent' width='450' height='250'></embed>" +
                "</object>";
        lblPreview3.Text = (randomMovies[2].preview.Equals("")) ? "Geen trailer beschikbaar" : "<object width='450' height='250'>" +
                    "<param name='movie' value='http://www.youtube.com/v/" + randomMovies[2].preview + "'></param>" +
                    "<param name='wmode' value='transparent'></param>" +
                    "<embed src='http://www.youtube.com/v/" + randomMovies[2].preview + "' type='application/x-shockwave-flash' wmode='transparent' width='450' height='250'></embed>" +
                "</object>";
    }

    protected void repeaterTopTen_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            Label lblMovieName = (Label)e.Item.FindControl("lblMovieName");
            Label lblMoviePosition = (Label)e.Item.FindControl("lblPositie");
            film movie = (film)e.Item.DataItem;

            int moviePos = ttm.getPosition(movie);

            lblMovieName.Text = movie.naam;
            lblMoviePosition.Text = moviePos.ToString();
        }
    }

    protected void comingSoonRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            Label lblMovieName = (Label)e.Item.FindControl("lblMovieName");
            film movie = (film)e.Item.DataItem;

            int moviePos = ttm.getPosition(movie);

            lblMovieName.Text = movie.naam;
        }
    }
}